import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { h } from "vue";
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '编号',
    dataIndex: 'no',
    align: 'center',
    helpMessage: '种植计划编号+2位自增流水号。例子：2023-1-1000-01-（计划编号）-01（自增流水号）'
  },
  {
    title: '种植计划',
    align: "center",
    dataIndex: 'growPlanId_dictText'
  },
  {
    title: '种植作物',
    align: "center",
    slots: { customRender: 'products' },
  },
  {
    title: '投入品',
    align: "center",
    slots: { customRender: 'inputs' },
    dataIndex: 'input_dictText'
  },
  {
    title: '用法与用量',
    align: "center",
    dataIndex: 'usageAndDosage',
    defaultHidden: true
  },
  {
    title: '农事操作',
    align: "center",
    dataIndex: 'productionOperation_dictText'
  },
  {
    title: '作业要求',
    align: "center",
    dataIndex: 'operationDescription'
  },
  {
    title: '作业开始时间',
    align: "center",
    dataIndex: 'jobStartTime',
    customRender: ({ text }) => {
      return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
    },
  },
  {
    title: '作业周期',
    align: "center",
    dataIndex: 'jobDuration',
    defaultHidden: true
  },
  {
    title: '作业工艺',
    align: "center",
    dataIndex: 'jobIntroduce',
    defaultHidden: true
  },
  {
    title: '是否临时安排',
    align: "center",
    dataIndex: 'randomJob_dictText',
    defaultHidden: true
  },
  {
    title: '计划操作人',
    align: "left",
    slots: { customRender: 'sysUsers' },
    ellipsis: true,
    // customRender: ({ record }) => {
    //   if (record.sysUsers.length){
    //     return record.sysUsers.map(item => item.realname).join(',');
    //   }
    //   return  '';
    //  },
  },
  {
    title: '计划状态',
    align: "center",
    dataIndex: 'statusDescription',
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "编号",
    field: 'no',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: '农事操作',
    field: 'productionOperation',
    colProps: { span: 6 },
    component: 'JTreeSelect',
    componentProps: {
      dict: "t_classification,name,id",
      pidField: "pid",
      pidValue: "1689815136974086145",
      hasChildField: "has_child",
    },
  },
  // {
  //   label: '是否临时安排',
  //   field: 'randomJob',
  //   component: 'JDictSelectTag',
  //   componentProps: {
  //     dictCode: 'yn',
  //     placeholder: '请选择是否临时安排',
  //   },
  //   colProps: { span: 6 },
  //   show: false
  // },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '种植计划',
    field: 'growPlanId',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 't_grow_plan,id,id',
      placeholder: '请选择种植计划',
    },
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请选择种植计划!' },
      ];
    },
  },
  {
    label: '农事操作',
    field: 'productionOperation',
    component: 'JTreeSelect',
    componentProps: {
      dict: "t_classification,name,id",
      pidField: "pid",
      pidValue: "1689815136974086145",
      hasChildField: "has_child",
      placeholder: '请选择农事操作',
    },
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请选择农事操作!' },
      ];
    },
    ifShow: ({ values }) => {
      return !!values.growPlanId
    }
  },
  {
    label: '投入品',
    field: 'input',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 't_inputs,name,id',
      placeholder: '请选择投入品',
    },
    // dynamicRules: ({model,schema}) => {
    //   return [
    //     { required: true, message: '请选择投入品!'},
    //   ];
    // },
  },
  {
    label: '用法与用量',
    field: 'usageAndDosage',
    component: 'Input',
  },
  {
    label: '作业工艺',
    field: 'jobIntroduce',
    component: 'Input',
  },
  {
    label: '作业要求',
    field: 'operationDescription',
    component: 'InputTextArea',
    componentProps: {
      style: 'height: 150px'
    }
  },
  {
    label: '作业开始时间',
    field: 'jobStartTime',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      placeholder: '请选择作业开始时间',
    },
  },
  {
    label: '作业周期',
    field: 'jobDuration',
    component: 'Input',
  },
  {
    label: '是否临时安排',
    field: 'randomJob',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'yn',
      placeholder: '请选择是否临时安排'
    },
  },
  {
    // todo 需要使用租户用户
    label: '计划操作人',
    field: 'jobUsers',
    component: 'JCheckbox',
    componentProps: {
      dictCode: 'sys_user,realname,id',
      placeholder: '请选择作业计划操作人',
    },
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请选择作业计划操作人!' },
      ];
    },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
];



/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
